using System;
using System.Collections.Generic;
using System.Linq;

namespace DataGeneration.Domain.Helpers
{
    /// <summary>
    /// Defines the type EnumHelper
    /// </summary>
    public static class EnumHelper
    {
        /// <summary>
        /// Converts the specified enum value.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="enumValue">The enum value.</param>
        /// <param name="ignoreCase">if set to <c>true</c> [ignore case].</param>
        /// <returns></returns>
        public static T Convert<T>(string enumValue,bool ignoreCase)
        {
            if (!typeof(T).BaseType.Equals(typeof(Enum)))
            {
                throw new Exception("Only Enum types can be processed by this method");
            }

            return (T)Enum.Parse(typeof(T), enumValue,ignoreCase);
        }

        /// <summary>
        /// Gets the enum list.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static IList<T> GetEnumList<T>()
        {
            if (!typeof(T).BaseType.Equals(typeof(Enum)))
            {
                throw new Exception("Only Enum types can be processed by this method");
            }

            return (from object value in Enum.GetValues(typeof (T)) select (T) value).ToList();
        }
    }
}